FROM php:7.1-fpm-jessie
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
        && sed -i 's|security.debian.org|mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list

# RUN apk add --update nginx supervisor bash 
# RUN  apk add zlib-dev libmcrypt-dev
# RUN apk --update add openssh openrc 


RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN docker-php-ext-install \
        mcrypt \
        mbstring \
        pdo_mysql \
        zip \
        bcmath

# RUN pecl install redis \
#     && docker-php-ext-enable redis 


RUN curl -fsSL 'https://github.com/phpredis/phpredis/archive/3.1.4.tar.gz' -o phpredis.tar.gz \
    && mkdir -p phpredis \
    && tar -xf phpredis.tar.gz -C phpredis --strip-components=1 \
    && rm phpredis.tar.gz \
    && ( \
        cd phpredis \
        && phpize \
        && ./configure --enable-redis \
        && make -j$(nproc) \
        && make install \
    ) \
    && rm -r phpredis \
    && docker-php-ext-enable redis




# RUN  rm -rf /var/cache/apk/* \
#     &&



RUN apt-get update \
&& apt-get install -y nginx supervisor vim

RUN  curl -sS https://install.phpcomposer.com/installer | php -- --install-dir=/usr/local/bin --filename=composer


# COPY src/ /var/www/

# ENV EBOSS_TEST_SRC /var/www/test
# ADD src/eboss.tar.gz $EBOSS_TEST_SRC
# ADD src/public.tar.gz /var/www/
# ADD src/laravel-vue-admin.tar.gz /var/www/

RUN mkdir -p /etc/nginx/sites-available && \
	mkdir -p /etc/nginx/sites-enabled && \
	mkdir -p /run/nginx

ADD supervisord.conf /etc/supervisord.conf
ADD nginx.conf /etc/nginx/nginx.conf
# ADD sites/*.conf /etc/nginx/sites-enabled/
ADD sites/default.conf /etc/nginx/sites-enabled/


RUN sed -i \
        -e "s/;listen.mode = 0660/listen.mode = 0666/g" \
        -e "s/;listen.owner = www-data/listen.owner = www-data/g" \
        -e "s/;listen.group = www-data/listen.group = www-data/g" \
        -e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" \
        -e "s/^;clear_env = no$/clear_env = no/" \
         /usr/local/etc/php-fpm.d/www.conf

# CMD /usr/bin/supervisord -n -c /etc/supervisord.conf


#为composer install 增加缓存
ENV EBOSS_TEST_SRC /var/www
# RUN mkdir /var/www/
ADD src/eboss-no-vendor.tar.gz $EBOSS_TEST_SRC


# RUN cd $EBOSS_TEST_SRC/eboss \
#         && composer install 

# ENV EBOSS_SRC /var/www/eboss
# COPY . $EBOSS_SRC
RUN mv $EBOSS_TEST_SRC/eboss/.env.docker $EBOSS_TEST_SRC/eboss/.env
RUN cd $EBOSS_TEST_SRC/eboss \
    && chown www-data:www-data /var/www -R \
    && composer install \
    && chmod -R 0777 $EBOSS_TEST_SRC/eboss/storage


# RUN mv /var/www/eboss/.env.testing /var/www/eboss/.env \
#         && cd /var/www/eboss \
#         && composer install \
#         && cd /var/www/laravel-vue-admin \
#         && composer install 


 











# ADD ./src/eboss.tar.gz /var/www/html/

# RUN mv /var/www/html/eboss/.env.docker /var/www/html/eboss/.env


# RUN cd /var/www/html/eboss \
#     && composer install 


# RUN chown www-data:www-data /etc/nginx -R && \
#     chown www-data:www-data /run/nginx && \
#     chown www-data:www-data /var/www/html -R \
#     chown www-data:www-data /var/lib/nginx -R 

 



# RUN  sed -i '/\#\!\/bin\/sh/a\php /var/www/html/eboss/artisan config:init' /usr/local/bin/docker-php-entrypoint
# # ENTRYPOINT ["docker-php-entrypoint"]

# RUN sed -i \
#         -e "s/;listen.mode = 0660/listen.mode = 0666/g" \
#         -e "s/;listen.owner = www-data/listen.owner = nginx/g" \
#         -e "s/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g" \
#         -e "s/^;clear_env = no$/clear_env = no/" \
#         /usr/local/etc/php-fpm.d/www.conf


ADD ssh/insecure_id_rsa /tmp/id_rsa
ADD ssh/insecure_id_rsa.pub /tmp/id_rsa.pub
RUN apt-get install -y openssh-server

#        && systemctl enable ssh
# RUN update-rc.d ssh defaults \
# && systemctl enable ssh.socket \
# && update-rc.d ssh enable

# RUN update-rc.d ssh enable
# EXPOSE 22
# CMD ["/usr/sbin/sshd", "-D"]


#安装kafka
RUN apt-get update && echo y | apt-get install -y python git
RUN git clone https://github.com/edenhill/librdkafka.git \
     && cd librdkafka \
     && ./configure && make && make install
RUN pecl install rdkafka   && docker-php-ext-enable rdkafka




RUN mkdir /root/.ssh/ \
        && rm -f /etc/service/sshd/down && \
    cat /tmp/id_rsa.pub >> /root/.ssh/authorized_keys \
        && cat /tmp/id_rsa.pub >> /root/.ssh/id_rsa.pub \
        && cat /tmp/id_rsa >> /root/.ssh/id_rsa \
        && rm -f /tmp/id_rsa* \
        && chmod 644 /root/.ssh/authorized_keys /root/.ssh/id_rsa.pub \
    && chmod 400 /root/.ssh/id_rsa 

ADD env.sh /root/env.sh 
RUN chmod +x /root/env.sh

CMD [ "/root/env.sh" ]
